
package vn.aptech.project.model.dao;
import java.sql.SQLException;
import vn.aptech.project.model.dto.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

public class  Customer_DAO extends CommonDAO {
 public Customer_DAO() throws ClassNotFoundException, SQLException, IOException {
 }


public Vector selectall() throws SQLException
{
String strSelect = "SELECT * FROM FS_customer";
return ExecSelect(strSelect);
}
public Vector selectByName(String obj) throws SQLException
{
String strSelect = "SELECT * FROM FS_customer where cust_name='"+obj+"'";
return ExecSelect(strSelect);
}
public int getCustomerIdByCust_name(String cust_name) throws SQLException, FileNotFoundException, IOException
{
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
             } catch (ClassNotFoundException ex)
            {
            Logger.getLogger(tblorder_DAO.class.getName()).log(Level.SEVERE, null, ex);
            }
            String connectionString = "jdbc:sqlserver://localhost:1433;databaseName=FurnitureSystem;user=sa;password=1234567";
            Connection con = DriverManager.getConnection(connectionString);
            Statement statement = con.createStatement();
            String str = "Select Customerid from FS_customer where cust_name='"+cust_name+"'";
            ResultSet rs = statement.executeQuery(str);
            rs.next();
            Vector vt = new Vector();
            vt.add(rs.getObject("Customerid"));
            int a =Integer.parseInt(String.valueOf(vt.get(0)));
            return a;

}
public int insert(Customer_DTO  obj) throws SQLException
{
String strInsert = "INSERT INTO FS_customer VALUES (N'"+  obj.getcust_name() +"'  ,"+ obj.getcontactno() +" ,N'"+ obj.getaddr() +"'  ,"+ obj.getTypeid() +")";
return  ExecNonQuery(strInsert);
}


public int update(Customer_DTO  obj) throws SQLException
{
String strUpdate = "UPDATE FS_customer SET cust_name= N'"+ obj.getcust_name()+"' ,"+"contactno= "+obj.getcontactno() +","+"addr= N'"+obj.getaddr() +"' ,"+"Typeid= "+obj.getTypeid() +"WHERE Customerid="+ obj.getCustomerid() ;
return  ExecNonQuery(strUpdate);
}


public int delete(int Customerid) throws SQLException
{
String strDelete = "DELETE FROM FS_customer WHERE Customerid="+Customerid;
return  ExecNonQuery(strDelete);
}
}

